<?php
        include_once 'xmlrpc.inc';
	include_once 'Session.php';

	class BikeInfo {
		private $bike_out;
		public function __construct($bike_out)
		{
			$this->bike_out = $bike_out;
		}
		public function getNome()
		{	
			return $this->bike_out['nome'];
		}
		public function getBiciDisponibili()
		{
			return $this->bike_out['bici_disponibili'];
		}
		public function getBiciTotali()
		{
			return $this->bike_out['bici_totali'];
		}
		public function isValido()
		{
			return $this->bike_out['valido'];
		}

	}
	class BikeSharing {
		private $token_id;
		private $url_bike_service;

		public function __construct() {
			$this->url_bike_service = new xmlrpc_client("http://muovi.roma.it/ws/xml/bike/1");
			$this->token_id = $_SESSION['token_id'];
		} 


		public function getBike() {
			$bike_req = new xmlrpcmsg('bike.Lista', array( new xmlrpcval($this->token_id, "string"), ));
			$result = $this->url_bike_service->send($bike_req);
			
			$bike_info_out = array();
			if (!$result->faultCode())
			{
				$value_bike_resp = $result->value();
				$resp = $value_bike_resp->structMem("risposta");
				for ($i = 0; $i < $resp->arraySize(); $i++)
				{
					$val = $resp->arrayMem($i);
					$id_sito = $val->structMem("id_sito")->scalarVal();
					$nome = $val->structMem("nome")->scalarVal();
					$bici_disponibili = $val->structMem("bici_disponibili")->scalarVal();
					$bici_totali = $val->structMem("bici_totali")->scalarVal();
					$valido = $val->structMem("valido")->scalarVal();
					$lat = $val->structMem("y")->scalarVal();
					$long = $val->structMem("x")->scalarVal();
					$n = array("nome"=>$nome,"bici_disponibili"=>$bici_disponibili,"bici_totali"=>$bici_totali, "valido"=>$valido); 
					$bike_info = new BikeInfo($n);
					$bike_info_out[] = $bike_info;
				}
			}
			else
			{
				throw new Exception("Errore richiesta bici disponibili<br/>");

			}
			return $bike_info_out;
		}
		
	}
?>
